#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: pipeline01.py 
@version:
@time: 2022/01/06 
"""
from TapClientCore.T04_logic.Dag01.dag.dag01 import DAG01
from TapClientCore.T03_api_body_templates.v1_api_body import DATAFLOW_SETTING_DEFAULT


class Pipeline01:
    def __init__(self, name=''):
        self.name = name
        self.setting = ...
        self.dag = DAG01()
        self.stage = None

    def _clone(self, stage):
        self.stage = stage
        return self

    @property
    def attr(self):
        return {
            'name': self.name,
            'stages': self.dag.stages,
            'setting': self.setting
        }

    def config(self, setting):
        tmp = DATAFLOW_SETTING_DEFAULT.copy()
        tmp.update(setting)
        self.setting = tmp

    def readFrom(self, source):
        return self._clone(source)

    def writeTo(self, sink, relations=''):
        self.dag.edge(self.stage, sink, relations)
        return self._clone(sink)
